package com.cens.mall.search.controller;

import com.cens.common.exception.BaseCodeEnum;
import com.cens.common.to.es.SkuESModel;
import com.cens.common.utils.R;
import com.cens.mall.search.service.CommoditySaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/search/save")
public class ElasticSearchSaveController {
    @Autowired
    private CommoditySaveService commoditySaveService;

    @PostMapping("/commodity")
    public R commodityStatusUp(@RequestBody List<SkuESModel> skuESModelList){
        boolean flag = false;
        try {
            flag = commoditySaveService.commodityStatusUp(skuESModelList);
        }catch (Exception e){
            log.error("ElasticSearchSaveController商品上架错误",e);
            return R.error(BaseCodeEnum.COMMODITY_UP_EXCEPTION.getCode(),BaseCodeEnum.COMMODITY_UP_EXCEPTION.getMsg());
        }
        if(flag){
            return R.ok();
        }else{
            return R.error(BaseCodeEnum.COMMODITY_UP_EXCEPTION.getCode(),BaseCodeEnum.COMMODITY_UP_EXCEPTION.getMsg());
        }
    }
}
